<?php

$class = $blog->GetCatList(1, 'ee_blog_categories2', $cat1FID);
$new_post = $blog->GetPostList(1, 0, '', '', $status, 1, 5);
$comments = $blog->GetCommentsList(1, $postid, 5);
$blogerlink = $blog->GetCatList(1, 'ee_blog_link');

?><form name="search" action="index.php" method="get"><input type="hidden" name="Cat1" value="0"><div id="search"><input type="text" class="text" name="Keywords" id="ikeywords" autocomplete="off"> <input type="submit" class="submit" value="搜 索"></div></form>
<!-- 相册
<div id="album"><div class="album-img"><h3>my friends</h3><p><img src="images/album/testimg.jpg" title="my friends" rel="friends"></p></div><div class="album-control"><span class="l" title="contorl left img"></span><span class="r" title="contorl right img"></span></div></div>
<div class="side-module"><h3>个人简介</h3><ul><li>前端开发工程师</li><li>昵称：<?php echo $user_info['F_USER_NICKNAME'] ?></li><li>MSN：<?php echo $user_info['F_USER_MSN'] ?></li><li>QQ：<?php echo $user_info['F_USER_QQ'] ?></li></ul></div>
-->
<div class="side-module" style="padding-top:14px"><h3><?php echo $cat1info['F_CATEGORIES_NAME'];
echo "分类</h3><ul>";
if($class)
{
	foreach($class as $value)
	{
		echo "<li><a href=\"index.php?Cat={$value['F_ID']}\" title=\"{$value['F_CATEGORIES_DESCRIPTION']}\">{$value['F_CATEGORIES_NAME']}</a> <font>(<em>";
		echo $value['F_CATEGORIES_POSTS']."</em>)</font></li>";
	}
}
?></ul></div><div class="side-module"><h3>最新文章</h3><ul><?php
if($new_post)
{
	foreach($new_post as $post)
	{
		echo "<li><a href=\"index.php?Action=Post&amp;Post={$post['F_ID']}\">";
		if(mb_strlen($post['F_POSTS_TITLE'])>30)
			echo utf8Substr($post['F_POSTS_TITLE'], 0, 30)."...";
		else
			echo $post['F_POSTS_TITLE'];
		echo "</a> <font>(<em>".$post['F_CATEGORIES_NAME']."</em>)</font> <span class=\"time\">".date("Y-m-d", $post['F_POSTS_ISSUE_DATE'])."</span></li>";
	}
}
?></ul></div><div class="side-module"><h3>最新评论</h3><ul><?php
if($comments)
{
	foreach($comments as $value)
	{
		echo "<li><a href=\"index.php?Action=Post&amp;Post={$value['F_ID_POSTS_INFO']}#comments\">";
		if(mb_strlen($value['F_COMMENTS_CONTENT'])>15)
			echo utf8Substr($value['F_COMMENTS_CONTENT'], 0 ,10)."...";
		else
			echo $value['F_COMMENTS_CONTENT'];
		if(empty($value['F_COMMENTS_USER_BLOG'])){
			echo "</a> / <font>".$value[F_COMMENTS_USER]."</font> <span class=\"time\">".date("Y-m-d", $value[F_COMMENTS_DATE])."</span></li>";
		}else{
			echo "</a> / <font><a target=\"_blank\" href=\"".$value[F_COMMENTS_USER_BLOG]."\">".$value[F_COMMENTS_USER]."</a></font> <span class=\"time\">".date("Y-m-d", $value[F_COMMENTS_DATE])."</span></li>";
		}
		
	}
}
?></ul></div><div class="side-module"><h3>好友Blog</h3><ul><?php
if($blogerlink)
{
	foreach($blogerlink as $linkNote)
	{
		echo "<li><a target=\"_blank\" href=\"".$linkNote['F_BLOG_LINK']."\">";
		echo $linkNote['F_BLOG_Name'];
		echo "</a> / <font>" .$linkNote['F_BLOG_USER']. "</font></li>";
	}
}
?></ul></div>
<div id="twitter_div" class="side-module">
<h3 style="margin:0" class="module-header">Twitter Updates</h3>
<ul class="module-list" id="twitter_update_list"></ul>
<a href="http://twitter.com/apple6" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a>
</div>
<div class="space-e"><a href="RSS.php" class="rss" rel="rss" target="_blank">RSS订阅</a></div>
<script type="text/javascript">

var autoSuggest = function(Obj){
	this.cur = -1; this.oInput = Obj.oInput; this.oTag = Obj.oTag; this.elClass = Obj.listClass;

	var oThis = this; //改变this作用域
	
	this.oTag.onmousedown = 
	this.oTag.onmouseup = 
	this.oTag.onmouseover = function(e){
		var el = E.getTarget(e);

		if(e.type=='mousedown'){
			oThis.oInput.value = el.firstChild.nodeValue;
			oThis.hideSuggestions();
		}else if(e.type=='mouseover'){
			oThis.highlightSuggestion(el);
		}else{
			oThis.oInput.focus();
		}
	};

    E.on(this.oInput, 'blur', function(){
    	oThis.hideSuggestions();
    });

    function setCoordinates(reference, setThing){
		var xy = D.getXY(reference);

		oTop = xy[1]+reference.offsetHeight;
		setThing.style.left = xy[0]+'px';
		setThing.style.top = oTop+'px';
		setThing.style.width = 232+'px';
		
		return xy;
    }

    E.on(this.oInput, 'keyup', function(e){
		//初始化坐标
		setCoordinates(oThis.oInput, oThis.oTag);
		
		var iKeyCode = e.keyCode;
		if(iKeyCode==8 || iKeyCode == 46){
			oThis.responseAjax();
		}else if(iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)){
			return false;
		}else{
			oThis.responseAjax();
		}
		oThis.cur = -1;
	});

	E.on(this.oInput, 'keydown', function(e){
		if (!e) {
            e = window.event;
        }
		oThis.handleKeyDown(e);
	});
};

autoSuggest.prototype = {
	handleKeyDown : function(e){
		switch(e.keyCode){
			case 38: //up arrow
				this.goToSug(-1);
				break;
			case 40: //down arrow
				this.goToSug(1);
				break;
			case 27: //esc
				this.hideSuggestions();
				break;
			case 13: //enter
			 	this.hideSuggestions();
	            break;
		}
	},
	goToSug : function(iDff){
		var sList = this.oTag.childNodes, len = sList.length;

		var oldLen = len;

		if(len>0){
			var oNode = null;
			
			if(iDff>0){
				if(this.cur < (len-1)){
					oNode = sList[++this.cur];
				}
			}else{
				if(this.cur > 0){
					oNode = sList[--this.cur];
				}
			}

			if(oNode){
				this.highlightSuggestion(oNode);
				this.oInput.value = oNode.firstChild.nodeValue;
			}
		}
		return len;
	},
	highlightSuggestion : function(oSuggestionNode){
		var sList = this.oTag.childNodes, len = sList.length;

		for(var i=0; i<len; i++){
			var oNode = sList[i];
			if (oNode == oSuggestionNode) {
	            oNode.className = this.elClass;
	        } else if (oNode.className == this.elClass) {
	            oNode.className = "";
	        }
		}
	},
	hideSuggestions : function(){
		this.oTag.style.display = 'none';
	},
	responseAjax : function(){
		var oInput = this.oInput, oThis = this;
		
		if(jav.lang.trim(oInput.value)==''){
			oThis.oTag.style.display = 'none';
		}else{
			var sUrl = 'search-suggest.php?keywords='+encodeURIComponent(oInput.value)+ '&amp;timeStamp=' + (new Date()).getTime();
			AJAX('GET', sUrl, function(o){
				
				var oB = JSON.parse(o.responseText);
			
				var ohtml = '';
				
				for(var i=0, len=oB.length; i<len; i++){
					ohtml += '<p>'+oB[i]+'</p>';
				}
				
				oThis.oTag.innerHTML = ohtml;
				
				if(len>0){
					oThis.oTag.style.display = '';
				}else{
					oThis.oTag.style.display = 'none';
				}
				
			});
			
		}
	}
};

E.on(window, 'load', function(){

	var oInput = G('ikeywords'),oT = document.createElement('div'),oTop;

	oT.className = 'search-suggest';
	oT.style.display = 'none';
	document.body.appendChild(oT);
	
	var autoSugEg1 = new autoSuggest({
		oInput: oInput,
		oTag : oT,
		listClass : 'current'
	});

});
</script>
<script type="text/javascript" src="http://twitter.com/javascripts/typepad.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/apple6.json?callback=twitterCallback2&amp;count=5"></script>
